<?php
if (is_array($items)) :
    foreach ($items as $item) :
        if ($item->getLead() !== $item->getText() && $thread == '') continue;
        $messageId = $item->getId();
        $streamId = base64_decode($params[1]);
        $undefinedFilter = false;
        if ($_REQUEST['undefined'])
            $undefinedFilter = true;
        $messageTags = Tag::getTag($messageId, $streamId);
        $threadId = $item->getThreadId();
        $source = htmlspecialchars($item->getSource());
        $domain = parse_url($item->getURL(), PHP_URL_HOST);
        $date = new DateTime($item->getTime());
        $sentimentScore = Sentiment::getScore($messageId, $streamId);
        $sentimentColor = ($sentimentScore == 0) ? "#9bbb59" : ($sentimentScore > 0 ? "#4f81bd" : "#c0504d");
        if ($sentimentScore == -2)
            $sentimentColor = '#EEE';
        if ($undefinedFilter && $sentimentScore != -2)
            continue;
        ?><li class="mozaic-widget list-item story-signal mozaic-initialized widget-story_signal mention-content" messageid="<?php echo $messageId; ?>" threadid="<?php echo $threadId; ?>" streamid="<?php echo $streamId; ?>" style="margin-bottom: 2px">
            <div class="mention-container alert-container alert-story-container signal-green">
                <div class="mention-content blog_mention" style="position: relative;">
                    <div class="mention-core">
                        <div class="mention-core-wrapper" style="margin-bottom: 33px;">
                            <div>
                                <p class="mention-type additional-timestamp signals-additional-time" data-timestamp="<?php echo $timestamp; ?>" style="float: right;"><?php echo $date->format("M d Y h:m A"); ?></p>
                                <div class="resource-text-container" >
                                    <p class="mention-title" text='<a class="action-color-hover" href="<?php echo $item->getURL(); ?>" target="_blank"><?php echo htmlspecialchars($item->getThreadTitle()); ?></a>'><a class="action-color-hover" href="<?php echo $item->getURL(); ?>" target="_blank"><?php echo htmlspecialchars($item->getThreadTitle()); ?></a></p>
                                    <?php
                                    $parse = parse_url($item->getURL());
                                    $parsedSource = str_ireplace('www.', '', $parse["host"]);
                                    ?>

                                </div>
                                <div class="mention-text">
                                    <?php
                                    /* if (count($messageTags) == 0) {
                                      $tags = Tag::detectTag($text, $messageId, $streamId);
                                      if (count($tags) > 0)
                                      $messageTags = $tags;
                                      } */
                                    $text = trim(rtrim($item->getText(), 'null'));
                                    $text = htmlspecialchars(str_replace('(javascript:void(0))', '', $text));
                                    $text = str_replace("\n", "<br/>", $text);
                                    echo $text;
                                    ?>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php if ($thread == ''): ?><div class="view-thread" threadid="<?php echo $threadId ?>"><a class="unassigned">View Replies (<?php echo $item->totalReplies; ?>)</a></div><?php endif; ?>
                    <div class="sentiment-score" messageid="<?php echo $messageId ?>" threadid="<?php echo $threadId ?>" source="<?php echo $source; ?>" style="position: absolute; right: 10px; bottom: 30px; padding: 10px; border-radius: 5px 5px 0px 0px; background: <?php echo $sentimentColor; ?>">
                        <button score="1" class="possitive-button" <?php if ($sentimentScore == 1) echo "disabled=\"disabled\"" ?>>Positive</button>
                        <button score="0" class="neutral-button" <?php if ($sentimentScore == 0) echo "disabled=\"disabled\"" ?>>Neutral</button>
                        <button score="-1" class="negative-button" <?php if ($sentimentScore == -1) echo "disabled=\"disabled\"" ?>>Negative</button>
                    </div>
                    <div class="simple-tag" messageid="<?php echo $messageId ?>" threadid="<?php echo $threadId ?>" source="<?php echo $source; ?>" style="min-height: 30px; min-width: 100px; background-color: #EEE;padding: 0 4px;">
                        <?php
                        foreach ($messageTags as $tag) {
                            echo '<div class="tag-holder-container"><label>' . $tag->tagName . '</label><a tagid="' . $tag->tagId . '" class="remove-tag">x</a></div>';
                            if ($index >= 2)
                                $tagsTooltip[] = $tag->tagName;
                            $index++;
                        }
                        ?>
                    </div>
                </div>
            </div>
        </li>
        <?php
    endforeach;
    else : ?>
<?php endif; ?>
